package wli.java.file.util;

import static org.junit.Assert.*;

import java.util.Enumeration;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import wli.hibernate.db.Word;
import wli.hibernate.util.HibernateUtil;

public class TextFileReaderTest {

	@Test
	public void test() {
		TextFileReader tfr = new TextFileReader();
		tfr.setFilename("c:\\apache\\htdocs\\SPELLING_BEE\\words-01.txt");
		tfr.getContent();
		Enumeration<String> enums = tfr.getWordList().elements();
		String temp = null;
		Word word = null;
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = null;
int i=0;
		while (enums.hasMoreElements()) {
			word = new Word();
			temp = enums.nextElement();
			word.setWORD(temp);
			System.out.println(">>>>>>>>>>>>>>>"+temp);
			
			try {
				transaction = session.beginTransaction();
				System.out.println(">>>>>>>>>>>>>>>>>> [" + session.save(word)
						+ "] Saved.");

				transaction.commit();
			} catch (HibernateException e) {
				transaction.rollback();
				e.printStackTrace();
			} finally {
				session.close();
			}
			i++;
			if(i>10) break;
		}
	}

}
